package 集合作业1;
import java.util.Iterator;
import java.util.Scanner;

import com.company.Array;
import com.company.Test;
import oop继承第一章.Teacher;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

public class TestStudent {

    public static void main(String[] args) {
    Student student1=new Student(001,19,"刘家康","34260120011229621x");
    Student student2=new Student(002,20,"张凯鑫","342601200004196211");
    Student student3=new Student(003,18,"张子凡","342601200208306218");
    Student student4=new Student(004,19,"吕靓仔","342601200107146215");
    Student student5=new Student(005,20,"廖继闯","342601200001296213");
    /*
    * 泛型好处：类型更加安全，提高程序的性能，代码的重用。*/
    List<Student> students=new ArrayList<>();
    students.add(student1);
    students.add(student2);
    students.add(student3);
    students.add(student4);
    students.add(student5);
    System.out.println("学号\t\t"+"年龄\t\t"+"姓名\t\t\t"+"身份证");
    /*for (int i=0 ;i<students.size();i++){
         int id= (int)students.get(i).getId();
        System.out.println(id);
    }*/
        /*
        * 使用迭代器遍历集合*/
         Iterator<Student> it=students.iterator();
         while (it.hasNext()){
             Student student=it.next();
             System.out.println(student.getId()+"\t\t"+student.getName()+"\t\t"+student.getAge()+"\t\t"+student.getIdentity()+"\t\t");
         }
        System.out.println("。。。。。。。。。。。。。。。。。。。。。。。。。。。。。");
        /*
         *显示全部学员
         */
        for (Student student:students){
            System.out.println(student.getId()+"\t\t"+student.getAge()+"\t\t"+student.getName()+"\t\t"+student.getIdentity());
        }
        /*
        * 删除学员*/
        Scanner input=new Scanner(System.in);
        System.out.println("请输入你要删除的学员的学号：");
        int id=input.nextInt();
        for (Student student:students) {
            if (id==student.getId()){
                students.remove(id-1);
                break;
            }
        }
        /*
        * 删除指定学生后，显示删除后的学生信息列表*/
        for (Student student:students){
            System.out.println(student.getId()+"\t\t"+student.getAge()+"\t\t"+student.getName()+"\t\t"+student.getIdentity());
        }
        /*
        * 增加学员*/
        System.out.println("请输入学号：");
        int id1 = input.nextInt();
        System.out.println("请输入年龄：");
        int age1 = input.nextInt();
        System.out.println("请输入姓名：");
        String name1 = input.next();
        System.out.println("请输入身份证：");
        String  identity1=input.next();
        Student stu=new Student(id1,age1,name1,identity1);
        students.add(stu);
        /*
         * 增加指定学生后，显示删除后的学生信息列表*/
        for (Student student:students){
            System.out.println(student.getId()+"\t\t"+student.getAge()+"\t\t"+student.getName()+"\t\t"+student.getIdentity());
        }
        /*
         * 修改学员*/
        System.out.println("请输入你要修改的学生姓名");
        String name = input.next();
        for (Student student:students){
            if ( name==student.getName()){
                int s=students.indexOf(name);
                students.set(s,student);
            }
        }
        for (Student student:students){
            System.out.println(student.getId()+"\t\t"+student.getAge()+"\t\t"+student.getName()+"\t\t"+student.getIdentity());
        }
    }
}
